﻿var http = require('http');
http.createServer(function (req, res) {
    console.log('[200] ' + req.method + ' to ' + req.url);
    res.statusCode = 200;
    res.setHeader('Content_Type', 'text/html');
    setTimeout(setOrigin, 10 * 1000);

    function setOrigin() {
        var origin = req.headers['origin'];
        if (origin.indexOf('localhost') > -1) {
            res.writeHead(200, 'OK', {
                'Content-type': 'text/html',
                'Access-Control-Allow-Origin': origin
            });
        }
        res.write('<html><head><title>Fruit Total</title></head><body>');
        res.write('<p>');
        res.write('You selected ' + req.url.substring(1));
        res.write('</p></body></html>');
        res.end();
    }
}).listen(8080);